/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package btnhom;

import conn.JavaConnectDb;
import java.sql.Connection;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import oracle.jdbc.OraclePreparedStatement;
import oracle.jdbc.OracleResultSet;
import net.proteanit.sql.DbUtils;
/**
 *
 * @author nhung
 */
public class Nentdc {
    Connection conn = JavaConnectDb.ConnectDb();
    OraclePreparedStatement pst;
    OracleResultSet rs;
    
    private String man;
    private String tenn;
    private String chdai;
    private String chrong;
    private String capp;
    private String mloai;
    
     public String getMan() {
        return man;
    }
    public void setMan(String man) {
        this.man = man;
    }
    public String getTenn() {
        return tenn;
    }
    public void setTenn(String tenn) {
        this.tenn = tenn;
    }
    public String getChieudai() {
        return chdai;
    }
    public void setChieudai(String chdai) {
        this.chdai = chdai;
    }
    public String getChieurong() {
        return chrong;
    }
    public void setChieurong(String chrong) {
        this.chrong = chrong;
    }
     public String getCapphat() {
        return capp;
    }
    public void setCapphat(String capp) {
        this.capp = capp;
    }
   public String getMaloai() {
        return mloai;
    }
    public void setMaloai(String mloai) {
        this.mloai = mloai;
    }
    
    public OracleResultSet selectNen(){
        try{
            String sql = "select * from nen_tdc";
            pst=(OraclePreparedStatement) conn.prepareStatement(sql);
            rs = (OracleResultSet) pst.executeQuery();
            
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Khong the ket noi server");
        }
        return rs;  
    } 
    
    public void insertNen(String man, String tenn, String chdai, String chrong, String capp, String mloai)
    {
        try{
            String sql = "insert into nen_tdc(manen_tdc, tennen, chieudai, chieurong, capphat,maloai_nen) values(?,?,?,?,?,?)";
            pst=(OraclePreparedStatement) conn.prepareStatement(sql);
            pst.setString(1, man);
            pst.setString(2, tenn);
            pst.setString(3, chdai);
            pst.setString(4, chrong);
            pst.setString(5, capp);
            pst.setString(6, mloai);
            pst.executeQuery();
            JOptionPane.showMessageDialog(null, "Thanh Cong"); 
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Kiem tra lai ket noi hoac Ma nen");
        }
    }
    
    public void updateNen(String man, String tenn, String chdai, String chrong, String capp, String mloai)
    {
        try{
            JOptionPane.showMessageDialog(null, man);        
            String sql = "update nen_tdc set tennen=?, chieudai=?, chieurong=?, capphat=?, maloai=? where manen_tdc=?";
            pst=(OraclePreparedStatement) conn.prepareStatement(sql);
            pst.setString(1, tenn);
            pst.setString(2, chdai);
            pst.setString(3, chrong);
            pst.setString(4, capp);
            pst.setString(5, mloai);
            pst.setString(6, man);
            pst.executeQuery();
            JOptionPane.showMessageDialog(null, "Cap nhat thanh cong");        
         }catch(Exception e){
            JOptionPane.showMessageDialog(null,"khong ket noi duoc server");
        } 
    }
    
    public void deleteNen(String man)
    {
        try{
            String sql = "delete from nen_tdc where manen_tdc=?";
            pst=(OraclePreparedStatement) conn.prepareStatement(sql);
            pst.setString(1, man);
            pst.executeQuery();
            JOptionPane.showMessageDialog(null, "Xoa thanh cong");        
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Xoa khong thanh cong");
        } 
    }
    
}
